const douban=require("../../libraries/douban.js");
Page({
  data:{
    title:"",
    subtitle:"加载中...",
    loading:true,
    hasMore:true,
    page:1,
    size:20,
    type:'in_theaters',
    movies:[]
  },
doLoad(appand){
      douban.find(this.data.type,this.data.page++,this.data.size)
          .then(d=>{
                if (d.subjects&&d.subjects.length) {
                    
                    this.setData({subtitle:d.title,movies:this.data.movies.concat(d.subjects),loading:false});
                }else{
                    this.setData({ hasMore: false, loading: false })
                }
            }
          )
          .catch(e=>{
            this.setData({ subtitle: '获取数据异常', movies: [], loading: false })
            console.error(e)
          });
  },
  onLoad:function(params){
    this.data.title=params.title||this.data.title;
    this.data.type = params.type || this.data.type;
    this.doLoad();
  },
  loadMore:function(){
        if (!this.data.hasMore) return
       this.doLoad(true);
  },

  onReady:function(){
    wx.setNavigationBarTitle({title:this.data.title+" « 电影 « 豆瓣"});
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})